<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 1.创建函数，获取某个范围的随机整数，入参m,n
        function random(min, max) {
            let num = Math.floor(Math.random() * (max - min + 1)) + min;
            return num;
        }
        console.log(random(1, 10))


        // 2.一个圆的半径5，求这个圆的面积和周长分别是多少
        function round(r) {
            let perimeter = Math.PI * 2 * r;
            let area = Math.PI * Math.pow(r, 2);
            console.log(`该圆的周长为${perimeter}，面积为${area}`);
        }
        round(5)


        // 3.随机密码生成器   n位

        function password(length) {
            let pool = [
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
                "abcdefghijklmnopqrstuvwxyz",
                "0123456789",
                "!@#$%^&*"
            ];
            let password = [];
            let str = pool.join("")
            for (i = 0; i < length; i++) {
                if (i == 0) {
                    let j = Math.floor(Math.random() * 52);
                    password[i] = str[j];
                } else {
                    let j = Math.floor(Math.random() * str.length);
                    password[i] = str[j];
                }
            }
            return password;
        }
        let pw = password(16).join("")
        console.log(`您的密码为：“${pw}”`)


        function password2(length) {
            
            let password = [];
            let pool = [
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
                "abcdefghijklmnopqrstuvwxyz",
                "0123456789",
                "!@#$%^&*"
            ];
            for (i = 0; i < length; i++) {
                a = Math.floor(Math.random() * 4);
                if (a == 0 || a == 1) {
                    x =  Math.floor(Math.random() * 26);
                    password[i] = pool[a][x];
                }
                else if (a == 2) {
                    y = random(48, 57)
                    password[i] = String.fromCharCode(y);
                }
                else if (a == 3) {
                    y = Math.floor(Math.random() * 8);
                    password[i] = pool[a][y];
                }
            }
            return password;
        }
        let pw2 = password2(16).join("")
        console.log(`您的密码为：“${pw2}”`)
    </script>
</body>
</html>